package org.example.service;

import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

public class IpCountService {

    private Map<String,Integer> IpCountMap =  new HashMap<>();

    @Autowired
    private HttpServletRequest httpServletRequest;

    public void count(){
        //每次调用当前操作，记录当前访问的IP，累加访问次数
        String ip = httpServletRequest.getRemoteAddr();
        System.out.println(ip+"-----------");
        Integer count = IpCountMap.get(ip);
        if(count == null){
            IpCountMap.put(ip,1 );
        }else{
            IpCountMap.put(ip,count+1 );
        }

    }
}
